home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / prospero / PRM / src / testprog / r1sn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-24  |  1.6 KB  |  66 lines

  1. /*
  2.  * Copyright (c) 1992, 1993 by the University of Southern California
  3.  *
  4.  * For copying and distribution information, please see the files
  5.  * <prm-copyr.h>.
  6.  */
  7.  
  8. #include <prm-copyr.h>
  9.  
  10.  
  11. #include <stdio.h>
  12.  
  13. #define  MAIN_PROG
  14. #include <comm.h>   /*     This file defines certain constants, and declares
  15.             some global variables used by the message passing
  16.             routines.  */
  17.  
  18. #ifndef RNEIGH
  19. #   define RNEIGH(x,tot)    (x<tot)?x+1:1 /* right neighbor of x in the ring */
  20. #endif
  21.  
  22. #define MAX_ITER  5
  23. #define INT_SZ sizeof(int)
  24. #define SENDTO_PORT 1                     /* Port_id on destination task */
  25. #define RCVON_PORT  1                     /* Port on which to rcv messages */
  26.  
  27. char *progname;
  28.  
  29. main(argc, argv)
  30. int argc;
  31. char **argv;
  32. {
  33.   int i, j, ntasks, my_tid;
  34.   int time_dcrmt, timeleft, iter_cnt;
  35.   int sendto_task;
  36.  
  37.   init_task(argv);    /* Initialization is required for all tasks in every
  38.              application */
  39.   pfs_debug=0;
  40.   my_tid = gettid(); 
  41.   if (my_tid == -1) {
  42.     io_printf(" task could not get its tid!", (char *)0);
  43.     exit(1);
  44.   }
  45.   
  46.   ntasks = numtasks();   /* Total number of tasks in this job */
  47.  
  48.   for (iter_cnt = 1; iter_cnt <= MAX_ITER; iter_cnt++) {
  49.     if ( my_tid == 1 ) 
  50.       for (j = 2; j <= ntasks; j++ ) {
  51.     vrecv (j, RCVON_PORT, ANY_TAG, &i, INT_SZ);
  52.     io_printf( "(Task %d) received iteration %d from task %d (%d)", my_tid,
  53.         i, msg_sender(), j, (char *)0 );
  54.       }           
  55.     else {
  56.       io_printf ("(Task %d) sending  iteration %d to   task 1", my_tid, 
  57.            iter_cnt, (char *)0);
  58.       vsend (1, SENDTO_PORT, ANY_TAG, &iter_cnt, INT_SZ);
  59.     }
  60.   }
  61.   io_printf("task %d done.\n", my_tid, (char *)0 );
  62.   
  63.   exit(0);
  64. }
  65.  
  66.